﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace KTV项目
{
    public partial class chaxun : Form
    {
        public chaxun()
        {
            InitializeComponent();
        }
        Bestdao dao = new Bestdao();
        private void button1_Click(object sender, EventArgs e)
        {
            //将用户选择的查找条件放到数据库查询
            string sql = string.Format(@"select singer_info.singer_id,singer_name,singertype_name,singer_sex,singer_photo_url,singer_miao from singer_info inner join singer_type on singer_info.singertype_id=singer_type.singertype_id
where singer_name like '%{0}%' and singertype_name='{1}'", textBox1.Text,comboBox1.Text);
            dataGridView1.DataSource = dao.table(sql);   
        }

        private void chaxun_Load(object sender, EventArgs e)
        {
            //窗体加载时就将查询的歌手类别绑定到下拉框中
            string sql = "select singertype_id,singertype_name from singer_type";
            comboBox1.DataSource=dao.table(sql);
            comboBox1.DisplayMember = "singertype_name";
            comboBox1.ValueMember = "singertype_id";

        }
        string cha;
        private void 删除歌手信息ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //先判断是否有一条数据被选中
            if (dataGridView1.SelectedRows.Count==1)
            {
                //然后就先获得被选中的这一天数据
                DataGridViewRow row = this.dataGridView1.SelectedRows[0];
                cha = row.Cells[0].Value.ToString();
            }
            //将获得的这条数据的唯一值带入SQL语句去数据库里查询
            string sql = string.Format("delete from singer_info where singer_id={0}",cha);
            int he = dao.query(sql);
            if (he!=0)
            {
                //数据删除完成就提示数据删除成功
                MessageBox.Show("删除成功","提示",MessageBoxButtons.OK,MessageBoxIcon.Asterisk);
            }
            else
            {
                //否则就提示删除失败
                MessageBox.Show("删除失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
            //然后再用筛选的数据再查询一次，并填充到DGV框中显示
            string zhao = string.Format(@"select singer_info.singer_id,singer_name,singertype_name,singer_sex,singer_miao from singer_info inner join singer_type on singer_info.singertype_id=singer_type.singertype_id
where singer_name like '%{0}%' and singertype_name='{1}'", textBox1.Text, comboBox1.Text);
            dataGridView1.DataSource = dao.table(sql);
        }

        private void 编辑歌手信息ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //将本窗体用户选中的哪一行数据，传递给新打开的窗体来显示
            xiugai gai = new xiugai();
            if (dataGridView1.SelectedRows.Count==1)
            {
                DataGridViewRow row = this.dataGridView1.SelectedRows[0];
                gai.texid.Text=dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
                gai.tebname.Text = dataGridView1.SelectedRows[0].Cells[1].Value.ToString();
                gai.comtype.Text = dataGridView1.SelectedRows[0].Cells[2].Value.ToString();
                gai.texsex.Text = dataGridView1.SelectedRows[0].Cells[3].Value.ToString();
                gai.piclujing.ImageLocation = dataGridView1.SelectedRows[0].Cells[4].Value.ToString();
                gai.texmiao.Text = dataGridView1.SelectedRows[0].Cells[5].Value.ToString();     
            }
            gai.Show();
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }
    }
}
